package com.spx.core.wizards;

import java.util.Set;

import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;

import com.spx.core.CoreActivator;
import com.spx.core.types.Role;
import com.spx.core.types.User;
import com.spx.kernel.ui.widgets.DoubleListSelector;

/**
 * The "New" wizard page allows setting the container for the new file as well
 * as the file name. The page will only accept file name without the extension
 * OR with the extension that matches the expected one (mpe).
 */

public class NewUserRolesPage extends ModelWizardPage<User>
{
	private final User role = new User();
	private Text nameText;
	private DoubleListSelector<Role> selector;

	/**
	 * Constructor for SampleNewWizardPage.
	 * 
	 * @param pageName
	 */
	public NewUserRolesPage()
	{
		super("wizardPages");
		// setTitle("New User Role Details");
		setDescription("This User's Roles .");

	}

	/**
	 * @see IDialogPage#createControl(Composite)
	 */
	public void createControl(Composite parent)
	{

		final Composite container = new Composite(parent, SWT.NULL);
		final GridLayout layout = new GridLayout();
		container.setLayout(layout);
		layout.numColumns = 1;

		final Group roleComposite = new Group(container, SWT.NONE);
		roleComposite.setText("Select Roles");
		roleComposite.setLayout(layout);

		selector = new DoubleListSelector<Role>(roleComposite, SWT.NONE, getAllRoles(), role.getRoles());

		initialize();
		dialogChanged();
		setControl(roleComposite);
	}

	private Set<Role> getAllRoles()
	{
		final Set<Role> result = CoreActivator.getDefault().getSecurityService().fetchAllRoles(0, Integer.MAX_VALUE);
		return result;
	}

	/**
	 * Tests if the current workbench selection is a suitable container to use.
	 */

	private void initialize()
	{

	}

	/**
	 * Ensures that both text fields are set.
	 */

	private void dialogChanged()
	{

	}

	private void updateStatus(String message)
	{
		setErrorMessage(message);
		setPageComplete(message == null);
	}

	@Override
	public void setProperties(User user)
	{
		user.setRoles(selector.getChosen());

	}

	@Override
	protected void createPageControl(Composite parent)
	{
		// TODO Auto-generated method stub

	}
}
